package com.example.ancientpoetryintelligencejava.mapper;

import com.example.ancientpoetryintelligencejava.model.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @BelongsProject: ancient-poetry-intelligence-java
 * @BelongsPackage: com.example.ancientpoetryintelligencejava.mapper
 * @Author: ZhShy
 * @CreateTime: 2022-03-15 19:33
 * @Description:
 */
@Mapper
public interface QuestionMapper {

    /**
     * 0诗词是谁写的？
     *
     * @param poetryTitle
     * @return
     */
    @Select("SELECT poetName FROM poet where poetId in (select poetId from poetry_poet where poetryId in (select poetryId from poetry where poetryTitle like '${poetryTitle}%'))")
    List<String> poetOfPoetry_0(String poetryTitle);

    /**
     * 1诗词是什么朝代
     *
     * @param poetryTitle
     * @return
     */
    @Select("SELECT dynastyName FROM dynasty where dynastyId in (select dynastyId from poetry_dynasty where poetryId in (select poetryId from poetry where poetryTitle like '${poetryTitle}%'))")
    List<String> dynastyOfPoetry_1(@Param("poetryTitle") String poetryTitle);

    /**
     * 6诗词的内容
     *
     * @param poetryTitle
     * @return
     */
    @Select("SELECT poetryDetail FROM poetry where poetryTitle like '${poetryTitle}%';")
    List<String> detailOfPoetry_6(String poetryTitle);

    /**
     * 2诗人写了哪些诗
     *
     * @param poetName
     * @return
     */
    @Select("SELECT poetryTitle FROM poetry where poetryId in (select poetryId from poetry_poet where poetId in (select poetId from poet where poetName='${poetName}'))")
    List<String> poetryListOfPoet_2(String poetName);

    /**
     * 3诗人是什么朝代的
     *
     * @param poetName
     * @return
     */
    @Select("SELECT dynastyName FROM dynasty where dynastyId in (select dynastyId from poet_dynasty where poetId in (select poetId from poet where poetName='${poetName}'))")
    List<String> dynastyOfPoet_3(String poetName);

    /**
     * 4这个朝代有哪些诗人
     *
     * @param dynastyName
     * @return
     */
//    @Select("match(n:Dynasty)-[r:Poet_dynasty]-(b:Poet) where n.dynastyName='${dynastyName}' return b.poetName")
    @Select("SELECT poetName FROM poet where poetId in (select poetId from poet_dynasty where dynastyId in (select dynastyId from dynasty where dynastyName='${dynastyName}'))")
    List<String> poetListOfDynasty_4(String dynastyName);

    /**
     * 5这个朝代有哪些作品
     *
     * @param dynastyName
     * @return
     */

//    @Select("match(n:Dynasty)-[r:Poetry_dynasty]-(b:Poetry) where n.dynastyName='${dynastyName}' return b.poetryTitle")
    @Select("SELECT poetryTitle FROM poetry where poetryId in (select poetryId from poetry_dynasty where dynastyId in (select dynastyId from dynasty where dynastyName='${dynastyName}'))")
    List<String> poetryListOfDynasty_5(String dynastyName);


    /**
     * 导出data词库
     *
     * @return
     */

    @Select("select poetName from poet")
    List<String> poetName();

    @Select("select poetryTitle from poetry")
    List<String> poetryTitle();

    @Select("select dynastyName from dynasty")
    List<String> dynastyName();


    /**
     * 新增 查询有无
     *
     * @param poetName
     * @return
     */
    @Select("select poetId from poet where poetName='${poetName}'")
    Integer poetId(String poetName);

    @Select("select poetryId from poetry where poetryTitle='${poetryTitle}' and poetryDetail='${poetryDetail}'")
    Integer poetryId(String poetryTitle, String poetryDetail);

    @Select("select dynastyId from dynasty where dynastyName='${dynastyName}'")
    Integer dynastyId(String dynastyName);

    /**
     * 新增
     */

    @Insert("insert into poet (poetName) value ('${poetName}')")
    void insertIntoPoet(String poetName);

    @Insert("insert into poetry (poetryTitle, poetryDetail) values ('${poetryTitle}', '${poetryDetail}') ")
    void insettIntoPoetry(String poetryTitle, String poetryDetail);

    @Insert("insert into dynasty (dynastyName) value ('${dynastyName}')")
    void insertIntoDynasty(String dynastyName);

    @Insert("insert into poetry_poet (poetryId,poetId) values (${poetryId},${poetId})")
    void insertIntoPoetry_Poet(Integer poetryId, Integer poetId);

    @Insert("insert into poetry_dynasty (poetryId,dynastyId) values (${poetryId},${dynastyId})")
    void insertIntoPoetry_Dynasty(Integer poetryId, Integer dynastyId);

    @Insert("insert into poet_dynasty (dynastyId,poetId) values (${dynastyId},${poetId})")
    void insertIntoPoet_Dynasty(Integer dynastyId, Integer poetId);


    /**
     * 获取知识图谱节点
     */
    @Select("select * from Poet")
    List<Poet> selectPoet();
    @Select("select * from Poetry")
    List<Poetry> selectPoetry();
    @Select("select * from Dynasty")
    List<Dynasty> selectDynasty();
    @Select("select * from Poet_Dynasty")
    List<Poet_Dynasty> selectPoet_Dynasty();
    @Select("select * from Poetry_Dynasty")
    List<Poetry_Dynasty> selectPoetry_Dynasty();
    @Select("select * from Poetry_Poet")
    List<Poetry_Poet> selectPoetry_Poet();

}
